﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YXQ.Common.Helper;
using YXQ.Dao.ViewModel;
using YXQ.Service;

namespace YXQ.Manager.Manager
{
    public partial class DepartDetail : BaseAdminPage
    {

        DepartModel model = new DepartModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                GetDepart();
            }

        }

        private void GetDepart()
        {

            model = CenterService.departService.GetOneById(reqID);
            if (model != null)
            {

                //
                txtDepartName.Value = model.DepartName.ToString();

                //
                txtDepartNum.Value = model.DepartNum.ToString();

                //
                txtDepartPID.Value = model.DepartPID.ToString();
 

            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new DepartModel() : CenterService.departService.GetOneById(Convert.ToInt32(hfId.Value));
            //
            model.DepartName = txtDepartName.Value;

            //
            model.DepartNum = txtDepartNum.Value;

            //
            if (!string.IsNullOrEmpty(txtDepartPID.Value))
            {

                model.DepartPID = Convert.ToInt32(txtDepartPID.Value);
            }
            else {
                model.DepartPID = 0;
            }
            model.OrderId = 0;

            if (CenterService.departService.Save(model) > 0)
            {

                JsHelper.AlertAndClose(this, "数据保存成功！");
            }

        }

    }

}

